{template 'common/header'}
<style>
	/*多图上传*/
.multi-img-details{margin-top:.5em;}
.multi-img-details .multi-item{height: 150px; max-width: 150px; position:relative; float: left; margin-right: 18px;}
.multi-img-details .multi-item img{max-width: 150px; max-height: 150px;}
.multi-img-details .multi-item em{position:absolute; top: 0; right: -14px;}
</style>
<ul class="nav nav-tabs">
	<li><a href="{php echo $this->createWebUrl('order', array('op'=>'display'));}">运单列表</a></li>
	<li class="active"><a href="{php echo $this->createWebUrl('order', array('op'=>'edit' , 'id' => $id));}">{if empty($id)}添加运单{else}编辑运单{/if}</a></li>
</ul>

<div class="main">
	<form action="" method="post" class="form-horizontal form" id="form">
		<div class="panel panel-default">

			{if empty($id)}
			<div class="panel-heading">添加运单</div>
			{else}
			<div class="panel-heading">编辑运单 订单编号：{php echo $order['orderId']}</div>
			{/if}
			<div class="panel-body">
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label"><span style='color:red'>*</span>订单编号：</label>
					<div class="col-xs-12 col-sm-8">
						<input style="width: 50%;" type="text" name="order[orderId]" class="form-control" value="{$order['orderId']}" />
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label"><span style='color:red'>*</span>唛头：</label>
					<div class="col-xs-12 col-sm-8">
						<input style="width: 50%;" type="text" name="order[mark]" class="form-control" value="{$order['mark']}" />
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label"><span style='color:red'>*</span>品名：</label>
					<div class="col-xs-12 col-sm-8">
						<input style="width: 50%;" type="text" name="order[name]" class="form-control" value="{$order['name']}" />
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label"><span style='color:red'>*</span>件数：</label>
					<div class="col-xs-12 col-sm-8">
						<input style="width: 50%;" type="text" name="order[num]" class="form-control" value="{$order['num']}" />
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label"><span style='color:red'>*</span>计费重量：</label>
					<div class="col-xs-6 col-sm-4">
						<div class="input-group">
						<input type="text" name="order[weight]" class="form-control" value="{$order['weight']}" />
						<span class="input-group-addon">元/kg</span>
						</div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-2 col-sm-2 col-md-2 col-lg-2 control-label">寄件人姓名：</label>
					<div class="col-xs-2 col-sm-2">
						<input type="text" name="order[sender]" class="form-control" value="{$order['sender']}" />
					</div>

					<label class="col-xs-1 col-sm-1 col-md-1 col-lg-1 control-label" style="width:50px">电话：</label>
					<div class="col-xs-2 col-sm-2">
						<input type="text" name="order[smobile]" class="form-control" value="{$order['smobile']}" />
					</div>

					<label class="col-xs-1 col-sm-1 col-md-1 col-lg-1 control-label" style="width:50px">地址：</label>
					<div class="col-xs-4 col-sm-4">
						<input type="text" name="order[saddress]" class="form-control" value="{$order['saddress']}" />
					</div>
				</div>

				<div class="form-group">
					<label class="col-xs-2 col-sm-2 col-md-2 col-lg-2 control-label">收件人姓名：</label>
					<div class="col-xs-2 col-sm-2">
						<input type="text" name="order[receiver]" class="form-control" value="{$order['receiver']}" />
					</div>


					<label class="col-xs-1 col-sm-1 col-md-1 col-lg-1 control-label" style="width:50px">电话：</label>
					<div class="col-xs-2 col-sm-2">
						<input type="text" name="order[rmobile]" class="form-control" value="{$order['rmobile']}" />
					</div>

					<label class="col-xs-1 col-sm-1 col-md-1 col-lg-1 control-label" style="width:50px">地址：</label>
					<div class="col-xs-4 col-sm-4">
						<input type="text" name="order[raddress]" class="form-control" value="{$order['raddress']}" />
					</div>
				</div>

				<div class="form-group">
					<div class="col-xs-12 col-sm-9 col-md-10 col-lg-10 col-sm-offset-3 col-md-offset-2 col-lg-offset-2">
						<input type="hidden" name="id" value="{$order['id']}" />
						<input name="submit" type="submit" value="提交" class="btn btn-primary" />
						<input type="hidden" name="token" value="{$_W['token']}" />
					</div>
				</div>
			</div>
		</div>
	</form>
</div>

<script>
require(['jquery', 'util'], function($, util){

	function checkmobile(val){
		if (val == "")
        return false;
	    var number = val.replace(/[ ]/g,"");
		if(val.trim() == '')
		    return false;

	    var r = true;
	    var regx = /^(130|131|132|133|134|135|136|137|138|139|158|159|147)\d{8}$/;
	    var regx2 = /^(0130|0131|0132|0133|0134|0135|0136|0137|0138|0139|0158|0159|0147|0812|8090|2229)\d{8}$/;
	    var regx3 = /^\d{11}$/;
	    var regx4 = /^\d{12}$/;

	 //    if(number.length == 12)
	 //    {
	 //   	    if(regx4.exec(number) == null)
	 //            r = false;
	 //        else
	 //            r = true;
	 //    }
	 //    if(number.length == 11)
	 //    {
	 //         if(regx3.exec(number) == null)
	 //            r = false;
	 //        else
	 //            r = true;
		// }
	    return r;
	}



	$(function(){
		$('#form').submit(function(){
			if($('input[name="order[orderId]"]').val() == ''){
				util.message('请填写订单编号.');
				return false;
			}
			if($('input[name="order[mark]"]').val() == ''){
				util.message('请填写唛头.');
				return false;
			}

			if($('input[name="order[name]"]').val() == ''){
				util.message('请填写品名.');
				return false;
			}

			var re = /^[1-9]+[0-9]*]*$/;
			if(!re.test($('input[name="order[num]"]').val())){
				util.message('件数必须是正整数.');
				return false;
			}

			if(isNaN(parseFloat($('input[name="order[weight]"]').val()))){
				util.message('计费重量必须填写数字.');
				return false;
			}

			if($('input[name="order[sender]"]').val() == '' || $('input[name="order[smobile]"]').val() == '' || $('input[name="order[saddress]"]').val() == ''){
				util.message('请填写完整寄件人信息.');
				return false;
			}

			if($('input[name="order[receiver]"]').val() == '' || $('input[name="order[rmobile]"]').val() == '' || $('input[name="order[raddress]"]').val() == ''){
				util.message('请填写完整收件人信息.');
				return false;
			}


			if(!checkmobile($('input[name="order[smobile]"]').val())){
				util.message('请填写寄件人正确的手机号.');
				return false;
			}

			if(!checkmobile($('input[name="order[rmobile]"]').val())){
				util.message('请填写收件人正确的手机号.');
				return false;
			}

			return true;
		});
	});
});
require(['jquery', 'util'], function($, u){
	$(function(){
		u.editor($('.richtext')[0]);
	});
});
</script>

{template 'common/footer'}